package com.shop2cn.iapi.agentproducts.testcase;

import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.GetSelectionConditionBean;
import com.shop2cn.iapi.agentproducts.parameter.SaveSelectionConditionBean;
import com.shop2cn.iapi.agentproducts.service.GetSelectionConditionCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_depot_info;
/**
*查询选货筛选条件(分销小店查询上级设置的条件)Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetSelectionCondition{
	private static GetSelectionConditionBean getselectionconditionBean;
	private static GetSelectionConditionCall getselectionconditionCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询选货筛选条件(分销小店查询上级设置的条件)Test");
	}

	@Before
	public void caseUp() {
		getselectionconditionBean=new GetSelectionConditionBean();
		getselectionconditionCall=new GetSelectionConditionCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getselectionconditionCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private int MchId=501163178;
	private int AgentId = 501163179;
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSelectionCondition_001() {
		Logger.start(true,"编辑规则，代理查询上级设置的规则");
		//这个接口只能查询分销小店的上级 分销小店只有一个上级 普通的代理可能有多个商家
		try {
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByMchId(MchId);
			Integer StoreId = GodmchManageCallService.CreateStores(MchId, 20);

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			SaveSelectionConditionBean initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, StoreId, 1);
			initSaveSelectionCondition.setBrandIdList(Arrays.asList(addAgentProductBean.getBrandId()));
			initSaveSelectionCondition.setFirstCategoryIdList(Arrays.asList(addAgentProductBean.getCategoryId()));
			initSaveSelectionCondition.setDepotIdList(Arrays.asList(addAgentProductBean.getDepotId()));
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			getselectionconditionBean.setSupplierId(MchId);
			getselectionconditionBean.setAgentId(StoreId);
			getselectionconditionCall.setData(getselectionconditionBean);
			getselectionconditionCall.callService();			
			Logger.verifyEquals("200", getselectionconditionCall.getString("code"), "验证code");
			JsonObject data = getselectionconditionCall.getJsonObject().get("data").getAsJsonObject();
			Logger.verifyEquals(1, data.get("scope").getAsInt(),"验证scope");
			Logger.verifyEquals(addAgentProductBean.getBrandId(), data.getAsJsonArray("brandIdList").get(0).getAsInt(),"验证brandId");
			Logger.verifyEquals(addAgentProductBean.getCategoryId(), data.getAsJsonArray("firstCategoryIdList").get(0).getAsInt(),"验证firstCategoryId");
			Logger.verifyEquals(addAgentProductBean.getDepotId(), data.getAsJsonArray("depotIdList").get(0).getAsInt(),"验证depotId");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}